package com.cyan.note.mapper;

import com.cyan.note.entity.Worker;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 打手管理Mapper接口
 * 
 * @author ZhangzhenYu
 * @since 2025-01-15
 */
@Mapper
public interface WorkerMapper {

    /**
     * 分页查询打手列表
     */
    List<Worker> selectWorkerPage(
            @Param("shopId") Long shopId,
            @Param("nickname") String nickname,
            @Param("status") List<String> status,
            @Param("accountStatus") List<String> accountStatus,
            @Param("level") List<String> level,
            @Param("skillTags") List<String> skillTags,
            @Param("joinDateStart") LocalDateTime joinDateStart,
            @Param("joinDateEnd") LocalDateTime joinDateEnd,
            @Param("ratingRange") String ratingRange,
            @Param("sortBy") String sortBy,
            @Param("sortOrder") String sortOrder,
            @Param("offset") Integer offset,
            @Param("limit") Integer limit
    );

    /**
     * 查询打手总数
     */
    int countWorkers(
            @Param("shopId") Long shopId,
            @Param("nickname") String nickname,
            @Param("status") List<String> status,
            @Param("accountStatus") List<String> accountStatus,
            @Param("level") List<String> level,
            @Param("skillTags") List<String> skillTags,
            @Param("joinDateStart") LocalDateTime joinDateStart,
            @Param("joinDateEnd") LocalDateTime joinDateEnd,
            @Param("ratingRange") String ratingRange
    );

    /**
     * 根据ID查询打手
     */
    Worker selectById(@Param("id") Long id);

    /**
     * 插入打手
     */
    int insert(Worker worker);

    /**
     * 更新打手
     */
    int updateById(Worker worker);

    /**
     * 删除打手
     */
    int deleteById(@Param("id") Long id);

    /**
     * 查询可用打手列表（用于订单分配）
     */
    List<Worker> selectAvailableWorkers(@Param("shopId") Long shopId);

    /**
     * 查询打手状态概览
     */
    WorkerStatusOverview selectWorkerStatusOverview(@Param("shopId") Long shopId);

    /**
     * 查询当前在线打手数量
     */
    Integer countOnlineWorkers(@Param("shopId") Long shopId);

    /**
     * 更新打手最后活跃时间
     */
    int updateLastActiveTime(@Param("workerId") Long workerId, @Param("lastActiveTime") LocalDateTime lastActiveTime);

    /**
     * 查询打手当前进行中的订单数
     */
    Integer countCurrentOrders(@Param("workerId") Long workerId);

    /**
     * 根据ID和店铺ID查询打手
     */
    Worker selectByIdAndShop(@Param("id") Long id, @Param("shopId") Long shopId);

    /**
     * 查询可分配给订单的打手列表
     */
    List<com.cyan.note.dto.manager.order.AvailableWorkerForOrderDTO> selectAvailableWorkersForOrder(@Param("params") java.util.Map<String, Object> params);

    /**
     * 打手状态概览结果
     */
    class WorkerStatusOverview {
        private Integer total;
        private Integer idle;
        private Integer working;
        private Integer rest;
        private Integer offline;

        // getters and setters
        public Integer getTotal() { return total; }
        public void setTotal(Integer total) { this.total = total; }
        public Integer getIdle() { return idle; }
        public void setIdle(Integer idle) { this.idle = idle; }
        public Integer getWorking() { return working; }
        public void setWorking(Integer working) { this.working = working; }
        public Integer getRest() { return rest; }
        public void setRest(Integer rest) { this.rest = rest; }
        public Integer getOffline() { return offline; }
        public void setOffline(Integer offline) { this.offline = offline; }
    }
}